package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/v1/vehicle/")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;
    @GetMapping("list")
    public JsonResult list(VehicleQuery vehicleQuery){
        log.debug("查询车辆列表{}",vehicleQuery);
        List<VehicleVO> list = vehicleService.list(vehicleQuery);
        return JsonResult.ok(list);
    }

    /**
     * 新增车辆
     * @param vehicleSaveParam
     * @return
     */
    @PostMapping("save")
    public JsonResult save(@RequestBody VehicleSaveParam vehicleSaveParam){
        log.debug("保存车辆信息{}",vehicleSaveParam);
        vehicleService.insert(vehicleSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("delete")
    public JsonResult delete(Long id){
        log.debug("删除车辆信息{}",id);
        vehicleService.delete(id);
        return JsonResult.ok();
    }

}
